/*
 * display.h
 *
 *  Created on: Dec 4, 2023
 *      Author: boen
 */

#ifndef PERIPHERALS_INC_DISPLAY_H_
#define PERIPHERALS_INC_DISPLAY_H_

#include <nvic.h>

#define HT16K33_SCL_L 		 	HAL_GPIO_WritePin(I2C_SCL_CH2_GPIO_Port, I2C_SCL_CH2_Pin, GPIO_PIN_RESET)
#define HT16K33_SCL_H 		 	HAL_GPIO_WritePin(I2C_SCL_CH2_GPIO_Port, I2C_SCL_CH2_Pin, GPIO_PIN_SET)

#define HT16K33_SDA_L 		 	HAL_GPIO_WritePin(I2C_SDA_CH2_GPIO_Port, I2C_SDA_CH2_Pin, GPIO_PIN_RESET)
#define HT16K33_SDA_H 		 	HAL_GPIO_WritePin(I2C_SDA_CH2_GPIO_Port, I2C_SDA_CH2_Pin, GPIO_PIN_SET)

#define HT16K33_ADDRESS 		0xE0

// Commands
#define HT16K33_ON              0x21  // 0=off 1=on
#define HT16K33_STANDBY         0x20  // bit xxxxxxx0


// bit pattern 1000 0xxy
// y    =  display on / off
// xx   =  00=off     01=2Hz     10=1Hz     11=0.5Hz
#define HT16K33_DISPLAYON       0x81
#define HT16K33_DISPLAYOFF      0x80
#define HT16K33_BLINKON0_5HZ    0x87
#define HT16K33_BLINKON1HZ      0x85
#define HT16K33_BLINKON2HZ      0x83
#define HT16K33_BLINKOFF        0x81

//#define HT16K33_DIM 0xE0|0x00 // Set dim from 0x00 (1/16th duty ccycle) to 0x0F (16/16 duty cycle)
#define HT16K33_DIM 			0xE0|0x00

// bit pattern 1110 xxxx
// xxxx    =  0000 .. 1111 (0 - F)
#define HT16K33_BRIGHTNESS      0xE0
#define BRILLIANCE				8	//背光亮度 0-15

void display_timer(void);

void display_init(void);
void display_deinit(void);
void display_polling(void);

#endif /* PERIPHERALS_INC_DISPLAY_H_ */
